package ee.karileet.ui.catalogue.view.fragment;

import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Table;
/**
 * Class is abstraction of Vaadin table generation. Specific tables must 
 * implement data source generation and visible and hidden field returning.
 * Then, a table can be invoked by using buildComponent method
 * @author Markus Karileet
 *
 */
public abstract class ATableView {

	/**
	 * Table to return
	 */
	private Table table = new Table();
	
	/**
	 * Method for table data source
	 * @return IndexedContainer as a data source for table
	 */
	protected abstract IndexedContainer containerDatasource();
	
	/**
	 * Method to return tables visible fields
	 * @return Array of Strings
	 */
	protected abstract String[] getVisibleFields();
	
	/**
	 * Method for all fields (used in data source)
	 * @return Array of Strings
	 */
	protected abstract String[] getFields();
	
	/**
	 * Method for building the table
	 * @return Table
	 */
	public Table buildComponent() {
		table.setContainerDataSource(containerDatasource());
		table.setVisibleColumns(getVisibleFields());
		table.setSelectable(true);
		table.setImmediate(true);
		return table;
	}
}
